#pragma once
/////////////////////////////////////////////////////////////////////////////////////////////////
const long max_page_control(32);
class __declspec(novtable) MyPageControl
{
public:
	void Create(long lPos,CPropertyPage*pPage,UINT uIDPage,CWnd*pWnd)
	{
		if(pPage->Create(uIDPage,pWnd))
		{
			pPage->EnableWindow(TRUE);
			pPage->ShowWindow(SW_HIDE);
			acProperty[lPos]=pPage;
		}
	}
	void OnSize(long x,long y,long cx,long cy)
	{
		for(long i(0);i<max_page_control;++i)
		{
			if(acProperty[i])
			{
				acProperty[i]->MoveWindow(x,y,cx,cy);
			}
		}
	}
	void Active(long lActive)
	{
		if(currActiving==lActive) return;
		if(currActiving>=0&&acProperty[currActiving])
		{
			acProperty[currActiving]->ShowWindow(SW_HIDE);
		}
		if(acProperty[currActiving=lActive])
		{
			acProperty[currActiving]->ShowWindow(SW_SHOW);
			acProperty[currActiving]->SetFocus();
			acProperty[currActiving]->Invalidate();
		}
	}
	void ActiveNext(void)
	{
		for(long i(currActiving+1);i<max_page_control;++i)
		{
			if(!acProperty[i]||!showFlag[i]) continue;
			Active(i);
			break;
		}
	}
	CPropertyPage*GetNext(void)
	{
		for(long i(currActiving+1);i<max_page_control;++i)
		{
			if(!acProperty[i]||!showFlag[i]) continue;
			return(acProperty[i]);
		}
		return(NULL);
	}
	void ActivePrev(void)
	{
		for(long i(currActiving-1);i>=0;--i)
		{
			if(!acProperty[i]||!showFlag[i]) continue;
			Active(i);
			break;
		}
	}
	CPropertyPage*GetPrev(void)
	{
		for(long i(currActiving-1);i>=0;--i)
		{
			if(!acProperty[i]||!showFlag[i]) continue;
			return(acProperty[i]);
		}
		return(NULL);
	}
	void OnDestory(BOOL blDelete=TRUE)
	{
		for(long i(0);i<max_page_control;++i)
		{
			if(acProperty[i])
			{
				acProperty[i]->DestroyWindow();
				if(blDelete) delete acProperty[i];
				acProperty[i] = NULL;
			}
		}
		currActiving = -1;
	}
	void OnOK(void)
	{
		for(long i(0);i<max_page_control;++i)
		{
			if(acProperty[i])
			{
				acProperty[i]->OnOK();
			}
		}
	}
	void AddIcon(UINT nIDIcon)
	{
		_imgList.Add((HICON)LoadImage(
			AfxFindResourceHandle(MAKEINTRESOURCE(nIDIcon),RT_GROUP_ICON),
			    MAKEINTRESOURCE(nIDIcon),IMAGE_ICON,0,0,0));
	}
	MyPageControl(void):currActiving(-1)
	{
		memset(acProperty,0,sizeof(CPropertyPage*)*max_page_control);
		memset(showFlag,0xFF,sizeof(showFlag));
		_imgList.Create(16,16,ILC_MASK|ILC_COLOR32,8,0);
	}
	~MyPageControl(void)
	{
	}
	CPropertyPage*acProperty[max_page_control];
	BOOL showFlag[max_page_control];
	CImageList _imgList;
	long currActiving;
};
